from flask import Flask
from extensions import db, login_manager
from routes.auth import auth_bp
from routes.user import user_bp
from routes.order import order_bp
from routes.storage import storage_bp
from routes.service import service_bp

def create_app():
    app = Flask(__name__)
    
    # 配置
    app.config['SECRET_KEY'] = 'your-secret-key'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///delivery.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    
    # 初始化扩展
    db.init_app(app)
    login_manager.init_app(app)
    
    # 注册蓝图
    app.register_blueprint(auth_bp, url_prefix='/auth')
    app.register_blueprint(user_bp, url_prefix='/user')
    app.register_blueprint(order_bp, url_prefix='/order')
    app.register_blueprint(storage_bp, url_prefix='/storage')
    app.register_blueprint(service_bp, url_prefix='/service')
    
    # 创建数据库表
    with app.app_context():
        db.create_all()
    
    return app 